
layui.config({
  base: '/layuiadmin/'
}).extend({
  index: 'lib/index' //主入口模块
}).use(['index'], function(){

  var $ = layui.$
  ,form = layui.form
  ,admin = layui.admin;
  var uid = layui.router().search.id;
  


  admin.req({
    type:"GET",
    url:"/api/admin/role/listALL",     
    dataType:"json",
    success:function(res){
        // 表示是修改数据
        var data = res.data;
       var io= $('.roleIdLists').html()
        if(res.code==200){
          var html ="";
          $.each(data, function(index,item) {
            html += '<input type="checkbox" lay-skin="primary" name="roleIdList[]" title="'+item.name+'" value="'+item.id+'">';
          }); 
          $('.roleIdLists').append(html);
          form.render(); 
        }
       
    },
    error:function(jqXHR){
        alert("发生错误："+ jqXHR.status);
    }
  });


  if(uid != undefined && uid != ""){
    admin.req({
        type:"GET",
        url:"/api/admin/user/"+uid,     
        dataType:"json",
        success:function(res){
            // 表示是修改数据
            var data = res.data;
            if(res.code==200){
                form.val('userForm', data);
                $.each(data.roleIdList, function(index,value) {
                  $("input[name='roleIdList[]'][value="+value+"]").attr("checked", 'checked') ;
                });
                form.render(); 
            }
           
        },
        error:function(jqXHR){
            alert("发生错误："+ jqXHR.status);
        }
      });
    
  }

  
  
});